﻿namespace Game
{
    public class Player
    {
        public enum ePlayerType 
        { 
            Mortal, 
            AI 
        }

        private ePlayerType m_PlayerType;
        private string m_Name;
        private int m_Score = 0;
        private AI m_AI;

        public Player(string i_Name, ePlayerType i_PlayerType)
        {
            m_Name = i_Name;
            m_PlayerType = i_PlayerType;
            if (i_PlayerType == ePlayerType.AI)
            {
                m_AI = new AI();
            }
        }

        public Engine.eInputType MakeMove(Board i_Board, out Board.Coordinate o_Move, bool i_IsFirstMoveInTurn)
        {
            Engine.eInputType inputType;

            if (m_PlayerType == ePlayerType.Mortal)
            {
                inputType = ConsoleIO.GetCommandFromPlayer(this, i_Board, out o_Move);
            }
            else if (m_PlayerType == ePlayerType.AI)
            {
                o_Move = m_AI.GetMove(i_Board, i_IsFirstMoveInTurn);
                inputType = Engine.eInputType.Move;
            }
            else
            {
                throw new System.Exception("Exception: Invalid player type at Player.MakeMove()\n");
            }

            return inputType;
        }

        public AI AI
        {
            get 
            {
                if (m_PlayerType == ePlayerType.AI)
                {
                    return m_AI; 
                }
                else
                {
                    throw new System.Exception("Tried to access AI functionality in a human player");
                }
            }

            private set { }     
	    }

        public ePlayerType PlayerType
        {
            get { return m_PlayerType; }
            private set { } 
        }
    
        public int Score
        {
            get { return m_Score; }
            set { m_Score = value; }
        }

        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }
    }
}
